<template>
  <div>
    <!-- 头部 -->
    <header>
      <span class="fangzi"><img src="./img/home.png" alt="" /></span>
      <div class="search">
        <form action="">
          <input
            type="text"
            placeholder="搜索本店商品"
            @input="sousuo"
            v-model="chacha"
          />
          <img src="./img/搜索.png" alt="" />
        </form>
      </div>
      <span class="more"><img src="./img/dian.png" alt="" /></span>
    </header>
    <!-- 导航 -->
    <ul class="nav">
      <li v-for="(i, item) in arrnav" :key="item" @click="qiedaohang(item)">
        <span :class="{ redbd: item == atmitem }">
          {{ i }}
        </span>
        <div v-if="zhengfan == true">
          <i v-if="shunxu == true"></i>
          <em v-if="shunxu == true"></em>
          <b v-if="shunxu == false"></b>
          <strong v-if="shunxu == false"> </strong>
        </div>
      </li>
      <li><img @click="qiehuan" src="./img/qiehuan.png" alt="" /></li>
    </ul>
    <!-- 主要内容 -->
    <main>
      <ul class="xuanran">
        <li
          v-for="(i, item) in arr"
          :key="item"
          :class="[ischu ? '' : 'dier']"
          v-if="soudeshihou == true"
        >
          <div>
            <img v-bind:src="i.pic" alt="" />
            <div>
              <span class="shangpin">{{ i.title }}</span>
              <p class="p1">
                <span class="red-pri">￥{{ i.price }}.00</span>
                <span class="red-man">满减</span>
              </p>
              <p class="p2">
                <span class="pingjia">{{ i.pj }}+条评价</span>
                <span class="haoping">好评{{ i.xiaoliang }}%</span>
              </p>
            </div>
          </div>
        </li>
        <!-- 搜索出来的 -->
        <li v-for="(i, item) in arrnew" :class="[ischu ? '' : 'dier']">
          <div>
            <img v-bind:src="i.pic" alt="" />
            <div>
              <span class="shangpin">{{ i.title }}</span>
              <p class="p1">
                <span class="red-pri">￥{{ i.price }}.00</span>
                <span class="red-man">满减</span>
              </p>
              <p class="p2">
                <span class="pingjia">{{ i.pj }}+条评价</span>
                <span class="haoping">好评{{ i.xiaoliang }}%</span>
              </p>
            </div>
          </div>
        </li>
      </ul>
    </main>
  </div>
</template>
<script>
export default {
  data() {
    return {
      atmitem: 0,
      ischu: true,
      chacha: "",
      soudeshihou: true,
      zhengfan: false,
      shunxu: false,
      ispaixu: true,
      arrnav: ["默认", "销量", "价格", "上新"],
      arr: [
        {
          title:
            "西铁城(CITIZEN)男士腕表 光动能小蓝针小牛皮表带时尚休闲生活防水商务手表 AO9000-06B七夕情人节礼物 送男友送老公",
          pic: require("./img/biao1.png"),
          xiaoliang: 96,
          manjian: true,
          price: "1282",
          time: 0,
          pj: 2000,
        },
        {
          title:
            "西铁城(CITIZEN)女士手表 光动能机芯不锈钢表带休闲时尚防水手表EW2530-87A七夕情人节礼物 送女友送老婆",
          pic: require("./img/biao2.png"),
          pj: 500,
          xiaoliang: 96,
          manjian: true,
          price: 1131,
          time: 1,
        },
        {
          title:
            "西铁城(CITIZEN)男士腕表 礼盒款光动能不锈钢表带绿水鬼表盘游泳防水商务手表 AW1598-70X七夕情人节礼物 送男友送老公",
          pic: require("./img/biao3.png"),
          xiaoliang: 95,
          manjian: true,
          price: 1613,
          pj: 2000,
          time: 11111,
        },
        {
          title:
            "  西铁城(CITIZEN)男士腕表 光动能电波钛金属运动/时尚防水手表JY8100-80E",
          pic: require("./img/biao4.png"),
          xiaoliang: 96,
          manjian: true,
          price: 4899,
          pj: 200,
          time: 105,
        },
        // { title: "", pic: "", xiaoliang: "", manjian: "", price: "", time: "" },
        // { title: "", pic: "", xiaoliang: "", manjian: "", price: "", time: "" },
        // { title: "", pic: "", xiaoliang: "", manjian: "", price: "", time: "" },
        // { title: "", pic: "", xiaoliang: "", manjian: "", price: "", time: "" },
        // { title: "", pic: "", xiaoliang: "", manjian: "", price: "", time: "" },
        // { title: "", pic: "", xiaoliang: "", manjian: "", price: "", time: "" },
        // { title: "", pic: "", xiaoliang: "", manjian: "", price: "", time: "" },
        // { title: "", pic: "", xiaoliang: "", manjian: "", price: "", time: "" },
        // { title: "", pic: "", xiaoliang: "", manjian: "", price: "", time: "" },
        // { title: "", pic: "", xiaoliang: "", manjian: "", price: "", time: "" },
      ],
      arrnew: [],
    };
  },
  methods: {
    qiedaohang(item) {
      this.atmitem = item;
      if (item == 0) {
        this.zhengfan = false;
        this.shunxu = false;
        this.arr = [
          {
            title:
              "西铁城(CITIZEN)男士腕表 光动能小蓝针小牛皮表带时尚休闲生活防水商务手表 AO9000-06B七夕情人节礼物 送男友送老公",
            pic: require("./img/biao1.png"),
            xiaoliang: 96,
            manjian: true,
            price: "1282",
            time: 0,
            pj: 2000,
          },
          {
            title:
              "西铁城(CITIZEN)女士手表 光动能机芯不锈钢表带休闲时尚防水手表EW2530-87A七夕情人节礼物 送女友送老婆",
            pic: require("./img/biao2.png"),
            pj: 500,
            xiaoliang: 96,
            manjian: true,
            price: 1131,
            time: 1,
          },
          {
            title:
              "西铁城(CITIZEN)男士腕表 礼盒款光动能不锈钢表带绿水鬼表盘游泳防水商务手表 AW1598-70X七夕情人节礼物 送男友送老公",
            pic: require("./img/biao3.png"),
            xiaoliang: 95,
            manjian: true,
            price: 1613,
            pj: 2000,
            time: 11111,
          },
          {
            title:
              "  西铁城(CITIZEN)男士腕表 光动能电波钛金属运动/时尚防水手表JY8100-80E",
            pic: require("./img/biao4.png"),
            xiaoliang: 96,
            manjian: true,
            price: 4899,
            pj: 200,
            time: 105,
          },
        ];
      } else if (item == 1) {
        this.zhengfan = false;
        this.shunxu = false;
        this.arr.forEach((item) => {
          this.arr.sort(function (a, b) {
            return a.xiaoliang - b.xiaoliang;
          });
        });
      } else if (item == 2) {
        console.log(item);
        this.zhengfan = true;
        if (this.zhengfan == true) {
          this.shunxu = !this.shunxu;
          if (this.shunxu == true) {
            this.arr.forEach((item) => {
              this.arr.sort(function (a, b) {
                return a.price - b.price;
              });
            });
          } else {
            this.arr.forEach((item) => {
              this.arr.sort(function (a, b) {
                return b.price - a.price;
              });
            });
          }
        }
      } else if (item == 3) {
        this.zhengfan = false;
        this.shunxu = false;

        this.arr.forEach((item) => {
          this.arr.sort(function (a, b) {
            return a.time - b.time;
          });
        });
      }
    },
    qiehuan() {
      this.ischu = !this.ischu;
    },
    sousuo() {
      this.arrnew = [];
      this.arr.forEach((item) => {
        if (this.chacha) {
          if (item.title.indexOf(this.chacha) != -1) {
            this.arrnew.push(item);
            this.soudeshihou = false;
          }
        } else {
          this.soudeshihou = true;
        }
      });
    },
  },
};
</script>
<style>
/* 主要内容 */
main {
  flex: 1;
  width: 100%;
  display: flex;
  flex-direction: column;
  background: #f2f2f7;
}
.red-pri {
  color: red;
}
.shangpin {
  font-size: 0.9rem;
}
.p1 {
  position: relative;
  font-size: 0.2rem;
  margin-bottom: 0.2rem;
}
.p2 {
  font-size: 0.2rem;
}
.red-man {
  color: red;
  font-size: 0.24rem;
  width: 2rem;
  height: 1rem;
  text-align: center;
  line-height: 1rem;
  position: absolute;
  margin-left: 1rem;
  margin-top: 0.1rem;
  border: 1px solid red;
}
main .xuanran .dier {
  width: 100%;
  height: 10rem;
}
main .xuanran .dier img {
  width: 8rem;
  height: 8rem;
}
main .xuanran .dier div {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: space-between;
}
main .xuanran .dier div div {
  display: flex;
  flex-direction: column;
  height: 75%;
}

.xuanran {
  display: flex;
  justify-content: space-between;
  width: 100%;
  flex-wrap: wrap;
  height: 100%;
}
.xuanran li {
  width: 50%;
  height: 15rem;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.xuanran li div {
  width: 90%;
  height: 15rem;
}
.xuanran li img {
  width: 100%;
  height: 10rem;
  border-radius: 0.5rem;
}
.shangpin {
  -webkit-line-clamp: 2;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
}
</style>
<style>
/* 头部+导航 */
header {
  padding: 0 0.3rem;
  height: 2.4rem;
  background: #fff;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-sizing: border-box;
}
/* 房子 */
.fangzi {
  width: 1.5rem;
  height: 1.5rem;
  display: flex;
}
.fangzi img {
  width: 1.5rem;
  height: 1.5rem;
}
/* 搜索框 */
.search {
  width: 60%;
  height: 2rem;
}
.search form {
  width: 100%;
  height: 100%;
  background: #f7f7f7;
  border-radius: 1.56rem;
  box-sizing: border-box;
  position: relative;
  padding-left: 2.4rem;
  display: flex;
  align-items: center;
}
.search form input {
  border: none;
  outline: none;
  background: #f7f7f7;
  color: #999;
}
.search form img {
  position: absolute;
  width: 1rem;
  height: 1rem;
  left: 0.5rem;
}
/* 更多按钮 */
.more img {
  width: 2rem;
  height: 0.5rem;
}
.nav {
  width: 100%;
  height: 2rem;
}
.nav {
  display: flex;
  height: 3rem;
  align-items: center;
  justify-content: space-between;
}

.nav li {
  width: 20%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.nav li span {
  color: #666;
  display: flex;
  width: 50%;
  justify-content: center;
  height: 2rem;
  align-items: center;
}
.nav li img {
  width: 40%;
  height: 40%;
}
.nav li:nth-child(3) {
  position: relative;
}
.nav li:nth-child(3) i {
  position: absolute;
  right: 0.5rem;
  bottom: 0.3rem;
  border-width: 0.3rem;
  border-color: #000 transparent transparent transparent;
  border-style: solid;
}
.nav li:nth-child(3) em {
  border-width: 0.3rem;
  right: 0.5rem;
  border-color: transparent transparent red transparent;
  border-style: solid;
  position: absolute;
  top: 0.4rem;
}
.nav li:nth-child(3) b {
  border-width: 0.3rem;
  right: 0.5rem;
  border-style: solid;
  bottom: 0.3rem;

  position: absolute;
  border-color: red transparent transparent transparent;
}
.nav li:nth-child(3) strong {
  top: 0.4rem;

  position: absolute;
  right: 0.5rem;
  border-width: 0.3rem;
  border-color: transparent transparent #000 transparent;
  border-style: solid;
}
/* 红色下边框 */
.redbd {
  border-bottom: 1px solid red;
  color: red !important;
}
</style>

<style>
/* 样式清空 */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

a {
  text-decoration: none;
}

ul,
li {
  list-style: none;
}

a,
input,
button {
  -webkit-tap-highlight-color: transparent;
  /* 移除点击产生的高亮效果：透明色 */
}

input,
button {
  -webkit-appearance: none;
  box-sizing: border-box;
  /* 在ios中加入这句能修改button和input的宽高 */
}

img,
a {
  -webkit-touch-callout: none;
  /* 禁止长按弹出菜单 */
}

img {
  vertical-align: middle;
}

/* 人造换轴 */
.row {
  flex-direction: row;
}

.column {
  flex-direction: column;
}
</style>
